package com.wuhainan.beelzebub.service.system;

import com.wuhainan.beelzebub.common.BaseService;
import com.wuhainan.beelzebub.entity.system.CategoryType;
import com.wuhainan.beelzebub.repository.system.CategoryTypeRepository;
import com.wuhainan.beelzebub.utils.PageInfo;
import com.wuhainan.beelzebub.utils.TableData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <br>Created by 吴海南 on 2017-12-18.
 * <br>星期一 at 下午 3:05.
 */
@Service
public class CategoryTypeService extends BaseService<CategoryType>{
    @Resource
    private CategoryTypeRepository repository;
    public List<CategoryType> findAll() {
        Sort sort=new Sort(Sort.Direction.ASC,"id");
        return repository.findAll(sort);
    }

    public TableData findCategoryTypePage(PageInfo pageInfo, CategoryType categoryType) {
        Page<CategoryType> page=repository.findAll((root, cq, cb) -> {
            search(categoryType, cq, cb, root);//模糊查询
            return cq.getRestriction();
        },pageable(pageInfo,sort(pageInfo, Sort.Direction.ASC,"id")));
        return tableData(page);
    }
    public CategoryType findCategoryTypeById(String id) {
        return repository.findOne(id);
    }

    /**
     * 保存类别类型
     *
     * @param categoryType 类别类型
     */
    public void saveCategoryType(CategoryType categoryType) {
        repository.save(categoryType);
    }

    /**
     * 删除类别类型
     *
     * @param categoryType 类别类型
     */
    public void deleteCategoryType(CategoryType categoryType) {
        repository.delete(categoryType);
    }

}
